﻿namespace BM.Tools.WebControls.MForm.Controls.Validators
{
    using System;

    using Additions;

    using Items;

    /// <summary>
    /// A class that keeps data about validation error caused by a failed constraint.
    /// </summary>
    public class FailedConstraintErrorCause : ErrorCause
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FailedConstraintErrorCause"/> class.
        /// </summary>
        /// <param name="errorControl">
        /// The error control.
        /// </param>
        /// <param name="errorConstraint">
        /// The error constraint.
        /// </param>
        public FailedConstraintErrorCause(OffspringItem errorControl, Constraint errorConstraint) : base(errorControl)
        {
            ErrorConstraint = errorConstraint;
        }

        /// <summary>
        /// Gets ErrorControl.
        /// </summary>
        public new OffspringItem ErrorControl
        {
            get
            {
                return base.ErrorControl as OffspringItem;
            }
        }

        /// <summary>
        /// Gets the constraint that caused the validation error.
        /// </summary>
        public Constraint ErrorConstraint
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the message that should be displayed when this error ocurred - it is the error text from the constraint.
        /// </summary>
        protected override string ErrorMessage
        {
            get
            {
                return ErrorConstraint.ErrorMessage;
            }
        }

        /// <summary>
        /// Gets the name of the error control
        /// </summary>
        protected override string ErrorControlName
        {
            get
            {
                return ErrorControl.DisplayName;
            }
        }
    }
}
